<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>留言本系统</title>
    <style>
        :root {
            --primary-color: #3498db;
            --secondary-color: #2980b9;
            --accent-color: #e74c3c;
            --light-color: #ecf0f1;
            --dark-color: #2c3e50;
            --success-color: #2ecc71;
            --warning-color: #f39c12;
            --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            --transition: all 0.3s ease;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Microsoft YaHei', sans-serif;
        }

        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #e4edf5 100%);
            color: #333;
            line-height: 1.6;
            padding: 20px;
            min-height: 100vh;
        }

        .container {
            max-width: 1000px;
            margin: 0 auto;
        }

        header {
            text-align: center;
            margin-bottom: 30px;
            padding: 20px;
            background: white;
            border-radius: 10px;
            box-shadow: var(--shadow);
            animation: fadeIn 0.8s ease-out;
            transition: var(--transition);
        }

        header:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0,0,0,0.12);
        }

        h1 {
            color: var(--dark-color);
            font-size: 2.5rem;
            margin-bottom: 10px;
            position: relative;
            display: inline-block;
        }

        h1:after {
            content: '';
            position: absolute;
            bottom: -5px;
            left: 50%;
            transform: translateX(-50%);
            width: 80px;
            height: 4px;
            background: var(--primary-color);
            border-radius: 2px;
            transition: var(--transition);
        }

        h1:hover:after {
            width: 120px;
            background: var(--accent-color);
        }

        .subtitle {
            color: #7f8c8d;
            font-size: 1.1rem;
        }

        .card {
            background: white;
            border-radius: 10px;
            box-shadow: var(--shadow);
            margin-bottom: 25px;
            overflow: hidden;
            transition: var(--transition);
        }

        .card:hover {
            transform: translateY(-8px);
            box-shadow: 0 12px 20px rgba(0, 0, 0, 0.15);
        }

        .card-header {
            background: var(--primary-color);
            color: white;
            padding: 15px 20px;
            font-weight: bold;
            font-size: 1.2rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
            transition: var(--transition);
        }

        .card-header:hover {
            background: var(--secondary-color);
        }

        .btn {
            display: inline-block;
            background: var(--primary-color);
            color: white;
            padding: 8px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 1rem;
            transition: var(--transition);
            text-decoration: none;
            transform-origin: center;
        }

        .btn:hover {
            background: var(--secondary-color);
            transform: translateY(-3px) scale(1.05);
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        }

        .btn:active {
            transform: translateY(1px) scale(0.98);
        }

        .btn-danger {
            background: var(--accent-color);
        }

        .btn-danger:hover {
            background: #c0392b;
            transform: translateY(-3px) scale(1.05);
        }

        .btn-outline {
            background: transparent;
            border: 2px solid var(--primary-color);
            color: var(--primary-color);
        }

        .btn-outline:hover {
            background: var(--primary-color);
            color: white;
            transform: translateY(-3px) scale(1.05);
        }

        .btn-success {
            background: var(--success-color);
        }

        .btn-success:hover {
            background: #27ae60;
            transform: translateY(-3px) scale(1.05);
        }

        .btn-sm {
            padding: 5px 12px;
            font-size: 0.9rem;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: var(--dark-color);
        }

        .form-control {
            width: 100%;
            padding: 12px 15px;
            border: 2px solid #ddd;
            border-radius: 5px;
            font-size: 1rem;
            transition: var(--transition);
        }

        .form-control:focus {
            border-color: var(--primary-color);
            outline: none;
            box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
        }

        .form-control:hover {
            border-color: #bbb;
        }

        textarea.form-control {
            min-height: 120px;
            resize: vertical;
        }

        .required:after {
            content: " *";
            color: var(--accent-color);
        }

        .message-item {
            border-bottom: 1px solid #eee;
            padding: 20px;
            animation: slideIn 0.5s ease-out;
            position: relative;
            transition: var(--transition);
            border-radius: 8px;
            margin: 10px 0;
        }

        .message-item:hover {
            background-color: #f8f9fa;
            transform: translateX(5px);
            box-shadow: 0 4px 8px rgba(0,0,0,0.05);
        }

        .message-item:last-child {
            border-bottom: none;
        }

        .message-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 10px;
        }

        .message-author {
            font-weight: bold;
            font-size: 1.1rem;
            color: var(--dark-color);
            transition: var(--transition);
        }

        .message-author:hover {
            color: var(--primary-color);
            transform: translateX(3px);
        }

        .message-time {
            color: #7f8c8d;
            font-size: 0.9rem;
            transition: var(--transition);
        }

        .message-time:hover {
            color: var(--dark-color);
        }

        .message-content {
            background: #f8f9fa;
            padding: 15px;
            border-radius: 5px;
            margin-bottom: 10px;
            line-height: 1.7;
            transition: var(--transition);
        }

        .message-content:hover {
            box-shadow: inset 0 0 0 1px rgba(52, 152, 219, 0.2);
        }

        .message-reply {
            background: #e8f4fd;
            border-left: 4px solid var(--primary-color);
            padding: 12px 15px;
            margin-top: 15px;
            border-radius: 0 5px 5px 0;
            transition: var(--transition);
        }

        .message-reply:hover {
            background: #d9edf9;
            border-left-width: 6px;
            transform: translateX(3px);
        }

        .reply-label {
            font-weight: bold;
            color: var(--primary-color);
            display: block;
            margin-bottom: 5px;
        }

        .reply-time {
            font-style: italic;
            font-size: 0.85rem;
            color: #7f8c8d;
            margin-top: 8px;
            text-align: right;
        }

        .contact-info {
            display: flex;
            gap: 15px;
            margin-top: 10px;
        }

        .contact-item {
            display: flex;
            align-items: center;
            gap: 5px;
            color: #7f8c8d;
            transition: var(--transition);
        }

        .contact-item:hover {
            color: var(--dark-color);
            transform: translateY(-2px);
        }

        .contact-item i {
            color: var(--primary-color);
        }

        .pagination {
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
            background: #f8f9fa;
            border-radius: 10px;
            margin-top: 20px;
        }

        .pagination a, .pagination span {
            display: inline-block;
            padding: 8px 16px;
            margin: 0 5px;
            text-decoration: none;
            color: var(--primary-color);
            border: 1px solid #ddd;
            border-radius: 5px;
            transition: var(--transition);
        }

        .pagination a:hover {
            background: var(--primary-color);
            color: white;
            border-color: var(--primary-color);
            transform: translateY(-3px);
        }

        .pagination .current {
            background: var(--primary-color);
            color: white;
            border-color: var(--primary-color);
        }

        .page-input {
            width: 60px;
            padding: 8px;
            text-align: center;
            border: 1px solid #ddd;
            border-radius: 5px;
            margin: 0 10px;
            transition: var(--transition);
        }

        .page-input:hover {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
        }

        .alert {
            padding: 15px;
            margin-bottom: 20px;
            border-radius: 5px;
            text-align: center;
            font-weight: bold;
            transition: var(--transition);
        }

        .alert:hover {
            transform: scale(1.02);
        }

        .alert-success {
            background: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }

        .alert-error {
            background: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }

        .admin-actions {
            display: flex;
            justify-content: flex-end;
            gap: 10px;
            margin-top: 15px;
        }

        .hidden {
            display: none;
        }

        .stats {
            display: flex;
            justify-content: space-around;
            text-align: center;
            margin: 25px 0;
        }

        .stat-item {
            padding: 15px;
            transition: var(--transition);
            border-radius: 8px;
            cursor: default;
        }

        .stat-item:hover {
            background: white;
            box-shadow: 0 5px 15px rgba(0,0,0,0.08);
            transform: translateY(-5px);
        }

        .stat-value {
            font-size: 2.5rem;
            font-weight: bold;
            color: var(--primary-color);
            margin-bottom: 5px;
            transition: var(--transition);
        }

        .stat-item:hover .stat-value {
            color: var(--secondary-color);
            transform: scale(1.1);
        }

        .stat-label {
            color: #7f8c8d;
            font-size: 0.9rem;
            transition: var(--transition);
        }

        .stat-item:hover .stat-label {
            color: var(--dark-color);
            font-weight: bold;
        }

        .admin-login-form {
            background: white;
            padding: 25px;
            border-radius: 10px;
            box-shadow: var(--shadow);
            max-width: 500px;
            margin: 0 auto 30px;
            transition: var(--transition);
        }

        .admin-login-form:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0,0,0,0.12);
        }

        .admin-login-form h3 {
            text-align: center;
            margin-bottom: 20px;
            color: var(--dark-color);
            position: relative;
            padding-bottom: 10px;
        }

        .admin-login-form h3:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 50%;
            transform: translateX(-50%);
            width: 60px;
            height: 3px;
            background: var(--primary-color);
            border-radius: 2px;
        }

        .admin-panel {
            background: rgba(236, 240, 241, 0.8);
            padding: 15px;
            border-radius: 8px;
            margin-top: 15px;
            border: 1px solid #ddd;
            transition: var(--transition);
        }

        .admin-panel:hover {
            background: rgba(220, 230, 240, 0.9);
            border-color: var(--primary-color);
            box-shadow: 0 4px 8px rgba(0,0,0,0.05);
        }

        .admin-panel h4 {
            margin-bottom: 10px;
            color: var(--dark-color);
            border-bottom: 1px solid #ddd;
            padding-bottom: 8px;
        }

        .admin-reply-form {
            margin-top: 10px;
        }

        .admin-reply-form textarea {
            min-height: 80px;
        }

        .admin-actions-row {
            display: flex;
            gap: 10px;
            margin-top: 10px;
            justify-content: flex-end;
        }

        /* 新增错误提示样式 */
        .error {
            color: #e74c3c;
            font-size: 0.85rem;
            margin-top: 5px;
            display: none;
        }

        .has-error .form-control {
            border-color: #e74c3c;
        }

        .has-error .error {
            display: block;
        }

        .message-item.new-message {
            animation: highlight 1.5s ease;
            border: 2px solid #3498db;
            border-left: 6px solid #3498db;
        }

        @keyframes highlight {
            0% { background-color: rgba(52, 152, 219, 0.1); }
            100% { background-color: white; }
        }

        @keyframes slideDown {
            from { opacity: 0; transform: translateY(-20px); }
            to { opacity: 1; transform: translateY(0); }
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(-20px); }
            to { opacity: 1; transform: translateY(0); }
        }

        @keyframes slideIn {
            from { opacity: 0; transform: translateX(-20px); }
            to { opacity: 1; transform: translateX(0); }
        }

        @keyframes pulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.05); }
            100% { transform: scale(1); }
        }

        @media (max-width: 768px) {
            .message-header {
                flex-direction: column;
                align-items: flex-start;
            }

            .message-time {
                margin-top: 5px;
            }

            .contact-info {
                flex-direction: column;
                gap: 8px;
            }

            .stats {
                flex-direction: column;
            }

            .pagination {
                flex-wrap: wrap;
            }

            .pagination a, .pagination span {
                margin: 5px;
            }

            .admin-actions {
                flex-direction: column;
                align-items: flex-end;
            }
        }
    </style>
</head>
<body>
<div class="container">
    <!-- 管理员登录表单 -->
    <div id="adminLogin" class="admin-login-form">
        <h3>管理员登录</h3>
        <div class="form-group">
            <label class="required">管理员账号</label>
            <input type="text" id="adminUsername" class="form-control" placeholder="请输入管理员账号" value="admin">
        </div>
        <div class="form-group">
            <label class="required">密码</label>
            <input type="password" id="adminPassword" class="form-control" placeholder="请输入密码" value="123456">
        </div>
        <div style="text-align: center; margin-top: 20px;">
            <button class="btn" onclick="adminLogin()">登录</button>
            <button class="btn btn-outline" onclick="adminLogout()">退出登录</button>
        </div>
    </div>

    <header>
        <h1>留言本系统</h1>
        <p class="subtitle">记录您的想法，分享您的观点</p>
    </header>

    <div class="stats">
        <div class="stat-item">
            <div class="stat-value">1,258</div>
            <div class="stat-label">总留言数</div>
        </div>
        <div class="stat-item">
            <div class="stat-value">328</div>
            <div class="stat-label">今日留言</div>
        </div>
        <div class="stat-item">
            <div class="stat-value">98%</div>
            <div class="stat-label">回复率</div>
        </div>
    </div>

    <div class="card">
        <div class="card-header">
            <span>留言列表</span>
            <div>
                <button class="btn" onclick="toggleForm()">发布留言</button>
                <span id="adminStatus" style="color: white; margin-right: 15px;">管理员已登录</span>
            </div>
        </div>

        <div class="card-body">
            <!-- 成功消息 -->
            <div id="successAlert" class="alert alert-success" style="display:none;">留言提交成功！</div>
            <div id="errorAlert" class="alert alert-error" style="display:none;"></div>

            <!-- 留言内容展示 -->
            <div class="message-item" id="message-1">
                <div class="message-header">
                    <div class="message-author">冰水晶</div>
                    <div class="message-time">2023-10-15 14:30:22</div>
                </div>
                <div class="message-content">
                    这个网站我用了很长时间了，真的很好很好，真希望以后出口整柜的可以查到每个提单号下提的集装箱的箱号封号，那就更完美了！！就像青岛一样！！
                </div>
                <div class="message-reply">
                    <span class="reply-label">管理员回复：</span>
                    这个网上其实可以查的。就是箱货信息里查了以后，点击详细页。进去有铅封号的。
                    <div class="reply-time">回复时间: 2023-10-15 15:45:11</div>
                </div>
                <div class="contact-info">
                    <div class="contact-item">
                        <i>📧</i> 270902697@qq.com
                    </div>
                    <div class="contact-item">
                        <i>👤</i> QQ: 270902697
                    </div>
                </div>
                <div class="admin-panel">
                    <h4>管理员操作</h4>
                    <div class="admin-reply-form">
                        <textarea class="form-control" id="reply-content-1" placeholder="请输入回复内容..."></textarea>
                        <div class="admin-actions-row">
                            <button class="btn btn-success btn-sm" onclick="submitReply(1)">提交回复</button>
                            <button class="btn btn-danger btn-sm" onclick="deleteMessage(1)">删除留言</button>
                        </div>
                    </div>
                </div>
            </div>

            <div class="message-item" id="message-2">
                <div class="message-header">
                    <div class="message-author">Carol</div>
                    <div class="message-time">2023-10-14 10:15:33</div>
                </div>
                <div class="message-content">
                    宁波EDI里每次进去都要输用户名和密码，而且时间一长要重新输入，比较麻烦，这个不用输就好了。
                </div>
                <div class="message-reply">
                    <span class="reply-label">管理员回复：</span>
                    确实比较麻烦，已经注意到了，我看看有没办法搞定他
                    <div class="reply-time">回复时间: 2023-10-14 11:20:45</div>
                </div>
                <div class="contact-info">
                    <div class="contact-item">
                        <i>📧</i> 819299425@qq.com
                    </div>
                    <div class="contact-item">
                        <i>👤</i> QQ: 819299425
                    </div>
                </div>
                <div class="admin-panel">
                    <h4>管理员操作</h4>
                    <div class="admin-reply-form">
                        <textarea class="form-control" id="reply-content-2" placeholder="请输入回复内容..."></textarea>
                        <div class="admin-actions-row">
                            <button class="btn btn-success btn-sm" onclick="submitReply(2)">提交回复</button>
                            <button class="btn btn-danger btn-sm" onclick="deleteMessage(2)">删除留言</button>
                        </div>
                    </div>
                </div>
            </div>

            <div class="message-item" id="message-3">
                <div class="message-header">
                    <div class="message-author">Jerry</div>
                    <div class="message-time">2023-10-12 12:15:33</div>
                </div>
                <div class="message-content">
                    很不错的网站呢，天天都用得着~~不过我发现个小问题，港区提单搜到箱号后，箱量多的，下一页按了跳不过去呢~~为啥会这样呢？是我电脑问题？可以前好的呀，怎么就最近都不行呢？
                </div>
                <div class="contact-info">
                    <div class="contact-item">
                        <i>📧</i> jerry0903@qq.com
                    </div>
                    <div class="contact-item">
                        <i>👤</i> QQ: 54500408
                    </div>
                </div>
                <div class="admin-panel">
                    <h4>管理员操作</h4>
                    <div class="admin-reply-form">
                        <textarea class="form-control" id="reply-content-3" placeholder="请输入回复内容...">我们正在检查分页功能的问题，感谢反馈！</textarea>
                        <div class="admin-actions-row">
                            <button class="btn btn-success btn-sm" onclick="submitReply(3)">提交回复</button>
                            <button class="btn btn-danger btn-sm" onclick="deleteMessage(3)">删除留言</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 发布留言表单 -->
    <div id="Ly" class="card hidden">
        <div class="card-header">写留言</div>
        <div class="card-body">
            <form id="messageForm" method="post">
                <div class="form-group">
                    <label class="required">昵称</label>
                    <input type="text" id="name" name="name" class="form-control" placeholder="请输入您的昵称" maxlength="10">
                    <div id="nameError" class="error">请输入昵称（1-10个字符，不含特殊符号）</div>
                </div>

                <div class="form-group">
                    <label class="required">QQ</label>
                    <input type="text" id="qq" name="qq" class="form-control" placeholder="请输入您的QQ号码">
                    <div id="qqError" class="error">请输入正确的QQ号码（5位以上数字）</div>
                </div>

                <div class="form-group">
                    <label class="required">邮箱</label>
                    <input type="email" id="email" name="email" class="form-control" placeholder="请输入您的邮箱">
                    <div id="emailError" class="error">请输入有效的邮箱地址</div>
                </div>

                <div class="form-group">
                    <label class="required">留言内容</label>
                    <textarea id="content" name="content" class="form-control" placeholder="请输入您的留言内容..."></textarea>
                    <div id="contentError" class="error">留言内容不能少于10个字符</div>
                </div>

                <div style="text-align: center;">
                    <button type="button" class="btn" style="padding: 10px 30px;" onclick="validateForm()">提交留言</button>
                    <button type="button" class="btn btn-outline" style="padding: 10px 30px;" onclick="resetForm()">重新填写</button>
                </div>
            </form>
        </div>
    </div>

    <!-- 分页导航 -->
    <div class="pagination">
        <a href="#">首页</a>
        <a href="#">上一页</a>
        <a href="#">1</a>
        <span class="current">2</span>
        <a href="#">3</a>
        <a href="#">4</a>
        <a href="#">5</a>
        <a href="#">下一页</a>
        <a href="#">尾页</a>

        <span style="margin-left: 20px;">页次：2/5 页</span>
        <span>共有 <span id="totalMessages">1258</span> 条留言</span>

        <span style="margin-left: 20px;">转到</span>
        <input type="text" id="pageInput" class="page-input" value="2">
        <button class="btn" onclick="goToPage()">GO</button>
    </div>
</div>

<script>
    // 管理员登录状态
    let isAdminLoggedIn = true;
    let messageCount = 3; // 初始留言数量
    let totalMessages = 1258; // 总留言数

    // 切换留言表单显示/隐藏
    function toggleForm() {
        const form = document.getElementById('Ly');
        form.classList.toggle('hidden');

        if (!form.classList.contains('hidden')) {
            form.scrollIntoView({ behavior: 'smooth' });
            resetForm();
        }
    }

    // 重置表单
    function resetForm() {
        document.getElementById('messageForm').reset();
        clearErrors();
    }

    // 清除所有错误提示
    function clearErrors() {
        const errors = document.querySelectorAll('.error');
        errors.forEach(error => error.style.display = 'none');

        const formGroups = document.querySelectorAll('.form-group');
        formGroups.forEach(group => group.classList.remove('has-error'));
    }

    // 表单验证
    function validateForm() {
        clearErrors();
        let isValid = true;

        // 验证昵称
        const name = document.getElementById('name').value.trim();
        if (!name) {
            showError('nameError', 'name');
            isValid = false;
        } else {
            const tChk = /^[^ \s~!@#$%\^\&\*\(\)_\+|\-\=\/\?:;'"\[\{\]\}`\.>,<\\]+$/;
            if (!tChk.test(name)) {
                showError('nameError', 'name');
                isValid = false;
            }
        }

        // 验证QQ
        const qq = document.getElementById('qq').value.trim();
        if (!qq) {
            showError('qqError', 'qq');
            isValid = false;
        } else if (qq.length < 5 || isNaN(qq)) {
            showError('qqError', 'qq');
            isValid = false;
        }

        // 验证邮箱
        const email = document.getElementById('email').value.trim();
        const emailChk = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
        if (!email) {
            showError('emailError', 'email');
            isValid = false;
        } else if (!emailChk.test(email)) {
            showError('emailError', 'email');
            isValid = false;
        }

        // 验证留言内容
        const content = document.getElementById('content').value.trim();
        if (!content) {
            showError('contentError', 'content');
            isValid = false;
        } else if (content.length < 10) {
            showError('contentError', 'content');
            isValid = false;
        }

        if (isValid) {
            submitMessage();
        }
    }

    // 显示错误信息
    function showError(errorId, fieldId) {
        const errorElement = document.getElementById(errorId);
        const fieldElement = document.getElementById(fieldId);

        if (errorElement && fieldElement) {
            errorElement.style.display = 'block';
            fieldElement.parentElement.classList.add('has-error');
        }
    }

    // 提交留言
    function submitMessage() {
        const name = document.getElementById('name').value.trim();
        const qq = document.getElementById('qq').value.trim();
        const email = document.getElementById('email').value.trim();
        const content = document.getElementById('content').value.trim();

        // 获取当前时间
        const now = new Date();
        const dateStr = now.getFullYear() + '-' +
            (now.getMonth()+1).toString().padStart(2, '0') + '-' +
            now.getDate().toString().padStart(2, '0') + ' ' +
            now.getHours().toString().padStart(2, '0') + ':' +
            now.getMinutes().toString().padStart(2, '0') + ':' +
            now.getSeconds().toString().padStart(2, '0');

        // 创建新的留言ID
        messageCount++;
        const newMessageId = 'message-' + messageCount;

        // 创建新的留言项
        const newMessageItem = document.createElement('div');
        newMessageItem.className = 'message-item new-message';
        newMessageItem.id = newMessageId;
        newMessageItem.innerHTML = `
            <div class="message-header">
                <div class="message-author">${name}</div>
                <div class="message-time">${dateStr}</div>
            </div>
            <div class="message-content">
                ${content}
            </div>
            <div class="contact-info">
                <div class="contact-item">
                    <i>📧</i> ${email}
                </div>
                <div class="contact-item">
                    <i>👤</i> QQ: ${qq}
                </div>
            </div>
            <div class="admin-panel" style="display: ${isAdminLoggedIn ? 'block' : 'none'}">
                <h4>管理员操作</h4>
                <div class="admin-reply-form">
                    <textarea class="form-control" id="reply-content-${newMessageId}" placeholder="请输入回复内容..."></textarea>
                    <div class="admin-actions-row">
                        <button class="btn btn-success btn-sm" onclick="submitReply('${newMessageId}')">提交回复</button>
                        <button class="btn btn-danger btn-sm" onclick="deleteMessage('${newMessageId}')">删除留言</button>
                    </div>
                </div>
            </div>
        `;

        // 添加到留言列表的顶部
        const cardBody = document.querySelector('.card-body');
        const firstItem = cardBody.querySelector('.message-item');

        if (firstItem) {
            cardBody.insertBefore(newMessageItem, firstItem);
        } else {
            cardBody.appendChild(newMessageItem);
        }

        // 显示成功消息
        const successAlert = document.getElementById('successAlert');
        successAlert.style.display = 'block';
        successAlert.style.animation = 'fadeIn 0.5s ease';

        // 更新统计信息
        totalMessages++;
        document.querySelector('.stat-value').textContent = totalMessages.toLocaleString();
        document.getElementById('totalMessages').textContent = totalMessages;

        // 重置表单
        resetForm();
        document.getElementById('Ly').classList.add('hidden');

        // 滚动到新添加的留言
        setTimeout(() => {
            newMessageItem.scrollIntoView({ behavior: 'smooth' });
        }, 300);

        // 3秒后隐藏成功消息
        setTimeout(() => {
            successAlert.style.display = 'none';
            newMessageItem.classList.remove('new-message');
        }, 3000);
    }

    // 删除留言
    function deleteMessage(id) {
        if (!isAdminLoggedIn) {
            alert('请先登录管理员账号！');
            return;
        }

        if (confirm('确定要删除这条留言吗？')) {
            const messageItem = document.getElementById(id);
            if (messageItem) {
                messageItem.style.opacity = '0';
                messageItem.style.transform = 'translateX(-100px)';
                messageItem.style.transition = 'all 0.5s ease';

                setTimeout(() => {
                    messageItem.remove();
                    // 更新统计信息
                    totalMessages--;
                    document.querySelector('.stat-value').textContent = totalMessages.toLocaleString();
                    document.getElementById('totalMessages').textContent = totalMessages;
                    alert('留言删除成功！');
                }, 500);
            }
        }
    }

    // 提交回复
    function submitReply(id) {
        const replyContent = document.getElementById('reply-content-' + id).value.trim();
        if (!replyContent) {
            alert('回复内容不能为空！');
            return;
        }

        // 获取当前时间
        const now = new Date();
        const dateStr = now.getFullYear() + '-' +
            (now.getMonth()+1).toString().padStart(2, '0') + '-' +
            now.getDate().toString().padStart(2, '0') + ' ' +
            now.getHours().toString().padStart(2, '0') + ':' +
            now.getMinutes().toString().padStart(2, '0') + ':' +
            now.getSeconds().toString().padStart(2, '0');

        // 创建回复元素
        const replyElement = document.createElement('div');
        replyElement.className = 'message-reply';
        replyElement.innerHTML = `
            <span class="reply-label">管理员回复：</span>
            ${replyContent}
            <div class="reply-time">回复时间: ${dateStr}</div>
        `;

        // 添加到留言中
        const messageItem = document.getElementById(id);
        const messageContent = messageItem.querySelector('.message-content');
        const existingReply = messageItem.querySelector('.message-reply');

        if (existingReply) {
            existingReply.replaceWith(replyElement);
        } else {
            messageContent.insertAdjacentElement('afterend', replyElement);
        }

        // 清空回复框
        document.getElementById('reply-content-' + id).value = '';

        // 添加动画效果
        replyElement.style.animation = 'pulse 0.6s ease';
        setTimeout(() => {
            replyElement.style.animation = '';
        }, 600);

        alert('回复提交成功！');
    }

    // 管理员登录
    function adminLogin() {
        const username = document.getElementById('adminUsername').value.trim();
        const password = document.getElementById('adminPassword').value.trim();

        if (!username || !password) {
            alert('管理员账号和密码不能为空！');
            return;
        }

        // 模拟登录验证
        if (username === 'admin' && password === '123456') {
            isAdminLoggedIn = true;
            alert('管理员登录成功！');

            // 添加登录成功效果
            document.getElementById('adminLogin').classList.add('hidden');
            document.getElementById('adminStatus').textContent = '管理员已登录';

            // 显示所有管理员面板
            document.querySelectorAll('.admin-panel').forEach(panel => {
                panel.style.display = 'block';
            });
        } else {
            alert('管理员账号或密码错误！');
        }
    }

    // 管理员退出登录
    function adminLogout() {
        isAdminLoggedIn = false;
        alert('您已退出管理员账号！');

        // 隐藏管理员操作面板
        document.querySelectorAll('.admin-panel').forEach(panel => {
            panel.style.display = 'none';
        });

        // 显示登录表单
        document.getElementById('adminLogin').classList.remove('hidden');
        document.getElementById('adminStatus').textContent = '';
    }

    // 跳转到指定页
    function goToPage() {
        const page = document.getElementById('pageInput').value;
        if (page && page > 0 && page <= 5) {
            alert('正在跳转到第 ' + page + ' 页');
        } else {
            alert('请输入有效的页码 (1-5)');
        }
    }

    // 页面加载时初始化
    window.onload = function() {
        // 设置初始管理员登录状态
        document.getElementById('adminLogin').classList.add('hidden');
        document.getElementById('adminStatus').textContent = '管理员已登录';
    };
</script>
</body>
</html>